package com.yidu.DailyFinalTreatment.mapper;

import com.yidu.DailyFinalTreatment.entity.OperationNetWorth;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

@Repository
@Mapper
public interface OperationNetWorthMapper {
    /**
     * 现金模块查询方法
     * @param dateTime
     * @param fundId
     * @param type
     * @return
     */
    @Select("\n" +
            "SELECT (cb.cashId)cashId,(c.accounName)accounName,(c.bankAccount)bankAccount,(cs.balance)balance,cashTotalAmount FROM (SELECT * FROM cash WHERE fundId=#{fundId})c\n" +
            "JOIN\n" +
            "(SELECT * FROM cashInventorys WHERE cashInventorysTime=#{dateTime} AND fundId=#{fundId})cs  ON c.cashId=cs.cashId\n" +
            "JOIN\n" +
            "(SELECT * FROM cashInventory WHERE cashInventoryTime=#{dateTime} AND fundId=#{fundId} AND businessType=#{type})cb ON cb.cashId=cs.cashId")
    public List<OperationNetWorth> selectOpertionNetWorth(String dateTime, String fundId, int type);

    /**
     * 现金模块查询方法-TA清算款
     * @param cashId
     * @param type
     * @param typeTwo
     * @return
     */
    @Select("SELECT IFNULL(SUM(cashTotalAmount),'')cashTotalAmount FROM cashInventory\n" +
            " WHERE cashId=#{cashId} AND  businessType=#{type} AND businessStatu=#{typeTwo} AND cashInventoryTime=#{dateTime} AND fundId=#{fundId}")
    public List<OperationNetWorth> selectOperationTA(String cashId, int type, int typeTwo, String dateTime, String fundId);


    /**
     * 运营模块查询方法-两费
     * @param dateTime
     * @param fundId
     * @param type
     * @return
     */
    @Select("SELECT * FROM cashInventory\n" +
            "WHERE cashId=#{cashId} AND cashInventoryTime=#{dateTime} AND fundId=#{fundId} AND businessType=#{type}")
    public List<OperationNetWorth> selectOperationCost(String cashId, String dateTime, String fundId, int type);
}
